/**
 * Created by chenshengli on 2015/7/9 0009.
 */
var showUsers = function () {
    $.ajax({
        type: "get",
        url: "/users/list",
        cache: false,
        success: function (users) {
            for (var i = 0; i < users.length; i++) {
                var user = users[i];
                $("#userSelect").append("<option value='" + user.uid + "'>" + user.name + "</option>");
            }
        }
    });
}

showUsers();


var isay = function () {
    var name = $("#userSelect").find("option:selected").text();
    var uid = $("#userSelect").val();
    var text = $('#says').val();
    if (!uid || uid == "") {
        alert("你是谁？");
        return;
    }
    if (!text || text == "") {
        alert("你什么都还没有说！");
        return;
    }
    $.ajax({
        type: "post",
        url: "/users/fuck",
        data: {
            name: name,
            uid: uid,
            text: text
        },
        cache: false,
        success: function (result) {
            if (result.status == "ok") {
                alert("发表成功");
            } else {
                alert("发表失败");
            }
            query();
        }
    });
}


var query = function () {
    $.ajax({
        type: "get",
        url: "/users/fuck",
        cache: false,
        success: function (fucks) {
            var html = "";
            for (var i = 0; i < fucks.length; i++) {
                var fuck = fucks[i];
                html+="<div style='margin-top: 10px;border: 1px solid #ddd;'><span class='fuck-user'>"+fuck.name+"</span>";
                html+="<span class='fuck-text'>"+fuck.text+"</span></div>";
            }
            $('#fucks').html(html);
        }

    });
}

query();